package com.googlecode.continuity.plugin.gwtext.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.*;
import com.googlecode.continuity.core.client.CoreGWT;
import com.googlecode.continuity.plugin.gwtext.client.message.GWTExtensionMessages;

/**
 * LoaderBox
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class LoaderBox extends CenteredDialogBox {
  private Label loadingText;

  private static final GWTExtensionMessages messages = (GWTExtensionMessages) GWT.create(GWTExtensionMessages.class);

  public LoaderBox() {
    this(messages.loading());
  }

  public LoaderBox(String text) {
    setText(messages.loading());
    addStyleName("loaderBox");
    Button cancel = new Button(messages.cancel(), finished);
    buttons.add(cancel);
    frame.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER);

    HorizontalPanel content = new HorizontalPanel();
    Image loaderImage = new Image(CoreGWT.getWebappRoot() + "img/loading_16.gif");
    content.add(loaderImage);
    loaderImage.addStyleName("loaderImage");
    loadingText = new Label();
    content.add(loadingText);
    loadingText.addStyleName("loaderMessage");
    frame.insert(content, 0);

    setLoadingText(text);
  }

  public void setLoadingText(String text) {
    loadingText.setText(text);
  }
}
